/**
 * 
 */
package org.huanglei.account.provider;

import java.lang.reflect.Constructor;

import android.content.Context;
import android.util.Log;

/**
 * @author huanglei
 * @data Jul 13, 2012
 */
public class DataProviderFactory {

	private static DataProvider dataProvider = null;

	public static final String LOCAL = "org.huanglei.account.provider.LocalDataProvider";

	private DataProviderFactory() {
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static DataProvider getProvider(Context context, String name) {
		if (dataProvider == null) {
			try {
				Class clazz = Class.forName(name);
				Constructor<DataProvider> constructor = clazz
						.getConstructor(Context.class);
				dataProvider = constructor.newInstance(context);
			} catch (Exception e) {
				Log.e("ProviderFactory",
						"Get dataprovider error[" + name + "]", e);
			}

		}
		return dataProvider;
	}
}
